package operation;

import book.Book;
import book.BookList;
import jdk.swing.interop.SwingInterOpUtils;

import java.util.Scanner;

public class Addbook implements Operate{
    @Override
    public void work(BookList books) {
        System.out.println("增加书籍...");
        int count=books.getUsedbooks();
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入新添加的书名:--->");
        String name=scanner.nextLine();

        System.out.print("请输入新添加书籍的作者:--->");
        String author=scanner.nextLine();

        System.out.print("请输入书籍的价格：--->");
        int price=scanner.nextInt();
        scanner.nextLine();
        System.out.print("请输入书籍的类型：--->");
        String type=scanner.nextLine();

        for(int i=0;i<count;i++) {
           if(books.getbook(i).getName().equals(name)){
               System.out.println("该书籍已经存在了，不需要添加-----");
               System.out.println();
               return ;
           }
        }
        Book book=new Book(name,author,price,type);
        books.setBooks(count,book);
        System.out.println("添加成功---");
        books.setUsedbooks(count+1);
        System.out.println();
    }
}
